// lib/theme/theme_manager.dart
import 'package:flutter/material.dart';
import 'app_theme.dart';

class ThemeManager with ChangeNotifier {
  ThemeData _currentTheme = AppTheme.lightTheme;

  ThemeData get currentTheme => _currentTheme;

  void toggleTheme() {
    _currentTheme = _currentTheme.brightness == Brightness.light
        ? AppTheme.darkTheme
        : AppTheme.lightTheme;
    notifyListeners();
  }

  // 添加缺失的setCustomTheme方法
  void setCustomTheme() {
    _currentTheme = ThemeData(
      colorScheme: ColorScheme.light(
        primary: Colors.purple,
        secondary: Colors.amber,
      ),
      brightness: Brightness.light,
      scaffoldBackgroundColor: Colors.grey[100],
      appBarTheme: AppBarTheme(
        backgroundColor: Colors.purple,
        titleTextStyle: const TextStyle(
          color: Colors.white,
          fontSize: 20,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
    notifyListeners();
        print("正在设置自定义主题"); // 添加日志
    _currentTheme = AppTheme.customTheme; // 使用预定义的主题
    notifyListeners(); // 确保调用了通知
    print("主题已更新为: ${_currentTheme.brightness}"); // 验证主题
  }

  void resetToSystemTheme(Brightness systemBrightness) {
    _currentTheme = systemBrightness == Brightness.dark
        ? AppTheme.darkTheme
        : AppTheme.lightTheme;
    notifyListeners();
  }
}